<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>设备报修</title>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
    <script src="js/ajax.js"></script>
</head>
<body >
<div id="app" >

    <div v-if="eq">
   设备名称： {{eq.name}}
   设备类型： {{eq.equipmentType.typeName}}
        <div>

            <img v-for="pic in eq.equipmentPics"
                 :src="pic.url+'&zoom=0.1'" width="30%" />
        </div>
    </div>

    <div class="weui-cells weui-cells_form">
        <div class="weui-cells__title">故障描述</div>
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <textarea
                            id="guzhang"

                            v-model="bxd.guzhang"
                            class="weui-textarea" placeholder="请输入故障" rows="3"></textarea>
                    <div class="weui-textarea-counter"><span>{{bxd.guzhang.length}}</span>/{{maxzishu}}</div>
                </div>
            </div>
        </div>
    </div>

    <a href="javascript:;" onclick="addBaoXiu()"
       style="width:90%;margin-top:20px;" class="weui-btn weui-btn_primary"
    >报修</a>

</div>

<!-- body 最后 -->
<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<!-- 如果使用了某些拓展插件还需要额外的JS -->
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/swiper.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/city-picker.min.js"></script>

<script src="js/getopenid.js"></script>
<script>
    getopenid(function(openid){
        alert(openid);
    });

    var v = new Vue({
        el: "#app",
        data: {
            eq:null,

            maxzishu:10,
            bxd:{
                baoXiuMan:{
                    openid:localStorage.openid
                },
                equipment:{
                    id:0
                },
                guzhang:''
            }
        }
    });

//    guzhang.onpaste = function(){
//        v.guzhang = "123";
//    }

    guzhang.onkeydown = function (e){
        if(e.keyCode==8){
            return true;
        }
        if(v.bxd.guzhang.length<10){
            return true;
        }
        return false;
    }


    var url = document.URL;
    var index = url.indexOf("eno=")
    var  eno = url.substring(index+4);
    //http://java59.hfbdqn.cn/baoxiu?eno=0000000012%26code%3D011MzSM3212q8Q0mSRK32SpPM32MzSM0%26state%3DSTATE
    $.get("/baoxiu?eno="+eno,null,function(data){
        v.eq = data;
        v.bxd.equipment = data;
    })

//    var xmlhttp  = new XMLHttpRequest();
//    xmlhttp.open("get","/baoxiu?eno="+eno,false);
//    xmlhttp.send();
//    xmlhttp.onreadystatechange = function(){
//        if(xhr.readyState==4&&xhr.status==200){
//                    v.eq = xmlhttp.responseText;
//                    v.bxd.equipment = xmlhttp.responseText;
//        }
//    }

    function addBaoXiu(){
        $.showLoading("请稍后..")
        ajax("add_baoxiu",v.bxd,function(data){
            console.log(data);
            $.hideLoading();

            $.showLoading("正在为您分配维修工程师..")

            waitNotify();
        })
    }

    function waitNotify(){
        //向谁通知
        var ws = new WebSocket("ws://java59.hfbdqn.cn/websocket/"+localStorage.openid);

        ws.onopen = function()
        {
            // Web Socket 已连接上，使用 send() 方法发送数据
            ws.send("发送数据");
            //alert("数据发送中...");
        };

        ws.onmessage = function (evt)
        {
            var received_msg = evt.data;
            //alert("数据已接收...");
            $.hideLoading();
           // alert(received_msg);
            received_msg = decodeURIComponent(received_msg);
            var showCnt = received_msg.substring(0,received_msg.indexOf("！"));
            var bxdid = received_msg.substring(received_msg.indexOf("！")+1);
            $.toast(showCnt,function(){
                location = 'repair_progress.html?bxdid='+ bxdid;
            });
            //跳转到修理进度页面
        };

        ws.onclose = function()
        {
            // 关闭 websocket
            //alert("连接已关闭...");
        };
    }
</script>

</body>
</html>